<?php

namespace App\Models;

use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Traits\AdminBuilder;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserProduct
 *
 * @property int $id
 * @property int|null $user_id
 * @property int|null $product_id
 * @property string|null $order_id
 * @property int|null $status
 * @property string|null $next_change_time
 * @property string|null $last_change_time
 * @property string|null $end_time
 * @property string|null $continue_time
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereContinueTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereEndTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereLastChangeTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereNextChangeTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereOrderId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereUserId($value)
 * @mixin \Eloquent
 * @property string|null $installed_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserProductEvent[] $eventFilter
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UserProductEvent[] $eventFix
 * @property-read \App\Models\Order|null $order
 * @property-read \App\Models\Product|null $product
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\UserProduct whereInstalledAt($value)
 */
class UserProduct extends Model
{
    use AdminBuilder;
    const STATUS_WAIT_INSTALL = 0;
    const STATUS_INSTALL = 1;
    public function order()
    {
        return $this->belongsTo(Order::class);
    }
    public function product()
    {
        return $this->belongsTo(Product::class);
    }
    public function eventFix(){
        return $this->hasMany(UserProductEvent::class)->where('type',UserProductEvent::EVENT_FIX);
    }

    public function eventFilter(){
        return $this->hasMany(UserProductEvent::class)->where('type',UserProductEvent::EVENT_FILTER);
    }

    public function event(){
        return $this->hasMany(UserProductEvent::class);
    }
}
